package com.hundsun.cprs.yyt.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.hundsun.cprs.yyt.service.trade.domain.TradeEntrust;
import com.hundsun.cprs.yyt.service.trade.domain.TradeMatch;
import com.hundsun.cprs.yyt.service.trade.domain.TradeMatchDetail;

public class TradeEntrustBeanUtil {
    
    public static com.hundsun.cprs.yyt.service.match.domain.TradeEntrust copyPropertiesFrom(TradeEntrust entrust){
        com.hundsun.cprs.yyt.service.match.domain.TradeEntrust tradeMatchEntrust = BeanUtils.transfrom(com.hundsun.cprs.yyt.service.match.domain.TradeEntrust.class, entrust);
        tradeMatchEntrust.setStockAccount(entrust.getFundAccount());
        tradeMatchEntrust.setEntrustNO(entrust.getEntrustNo());
        tradeMatchEntrust.setEntrustBS(entrust.getEntrustBs());
        tradeMatchEntrust.setCommissionrate(new BigDecimal(entrust.getCommissionRate()));
        tradeMatchEntrust.setMinCommission(0l);
        tradeMatchEntrust.setStockCode(entrust.getGoodsCode());
        tradeMatchEntrust.setDefaultFund(0l);
        tradeMatchEntrust.setDefaultAmount(0l);
        return tradeMatchEntrust;
    }
    
    public static TradeEntrust copyPropertiesFrom(com.hundsun.cprs.yyt.service.match.domain.TradeEntrust tradeMatchEntrust){
        TradeEntrust entrust = BeanUtils.transfrom(TradeEntrust.class, tradeMatchEntrust);
        entrust.setEntrustBs(tradeMatchEntrust.getEntrustBS());
        entrust.setGoodsCode(tradeMatchEntrust.getStockCode());
        entrust.setEntrustNo(tradeMatchEntrust.getEntrustNO());
        entrust.setCommissionRate(tradeMatchEntrust.getCommissionrate().intValue());
        return entrust;
    }
    
    public static List<TradeEntrust> copyPropertiesFrom(List<com.hundsun.cprs.yyt.service.match.domain.TradeEntrust> tradeMatchEntrustList){
        List<TradeEntrust> result = new ArrayList<TradeEntrust>();
        for(com.hundsun.cprs.yyt.service.match.domain.TradeEntrust item :  tradeMatchEntrustList){
            result.add(copyPropertiesFrom(item));
        }
        return result;
    }
    
    public static TradeMatch copyPropertiesFrom(com.hundsun.cprs.yyt.service.match.domain.TradeMatch tradeMatch){
        TradeMatch match = new TradeMatch();
        match.setMatchTime(tradeMatch.getMatchTime());
        match.setMatchPrice(tradeMatch.getMatchPrice());
        match.setMatchAmount(tradeMatch.getStockAmount());
        match.setGoodsCode(tradeMatch.getStockCode());
        match.setMatchSeq(tradeMatch.getMatchSeq());
        for(com.hundsun.cprs.yyt.service.match.domain.TradeMatchDetail item : tradeMatch.getMatchDetails()){
            TradeMatchDetail matchDetail = new TradeMatchDetail();
            matchDetail.setMatchAmount(item.getMatchStockAmount());
            matchDetail.setMatchCommission(item.getMatchCommission());
            matchDetail.setMatchFundAmount(item.getMatchFundAmount());
            matchDetail.setMatchManagement(item.getMatchManagementFund());
            matchDetail.setMatchPrice(item.getMatchPrice());
            matchDetail.setTransactions(tradeMatch.getTransactions());
            matchDetail.setTransactionCount(item.getTransactionCount());
            matchDetail.setSurplusEntrustAmount(item.getSurplusEntrustAmount());
            TradeEntrust entrust = copyPropertiesFrom(item.getEntrust());
            matchDetail.setEntrust(entrust);
            match.addTradeMatchDetail(matchDetail);
        }
        return match;
    }
    
}
